package cn.tedu._10bank.controller;

import cn.tedu._10bank.base.response.JsonResult;
import cn.tedu._10bank.mapper.CustomerMapper;
import cn.tedu._10bank.pojo.dto.CustomerAddParam;
import cn.tedu._10bank.pojo.entity.Customer;
import cn.tedu._10bank.pojo.vo.CustomerDetailAccountVO;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

@Slf4j
@Tag(name = "01-客户管理接口", description = "客户管理接口")
@RestController
@RequestMapping("/api/customer/")
public class CustomerController {


    @Autowired
    CustomerMapper customerMapper;


    @PostMapping("add")
    public JsonResult add(@RequestBody CustomerAddParam customerAddParam) {
        log.debug("用户添加"+customerAddParam);
        Customer customer = new Customer();
        BeanUtils.copyProperties(customerAddParam, customer);
        customer.setCreatedAt(new Date());
        customerMapper.insertCustomer(customer);
        return JsonResult.ok(customer);
    }


    @GetMapping("list")
    public JsonResult list() {
        List<Customer> list = customerMapper.selectCustomerList();
        return JsonResult.ok(list);
    }

    @GetMapping("{customerId}")
    public JsonResult get(@PathVariable Integer customerId) {
        List<CustomerDetailAccountVO> customerDetailAccountVOS = customerMapper.selectCustomerDetailAccountVO(customerId);
        return JsonResult.ok(customerDetailAccountVOS);
    }





















}
